// scrollToElement.js  
//   滚动出来函数
let scrollToElement = null
const ScrollToElementDirective = {
    mounted(el, binding) {

        // 传递需要移动到的容器id或class名
        const targetSelector = binding.value;
        const targetElement = document.querySelector(targetSelector);
        if (!targetElement) {
            console.warn(`No element found with selector: ${targetSelector}`);
            return;
        }
        scrollToElement = function () {

            targetElement.scrollIntoView({
                behavior: 'smooth',
                block: 'start',
                inline: 'center',
            });
        }
        el.addEventListener('click', scrollToElement);
    },
    unmounted(el, binding) {
        // 清理事件监听器（如果需要的话）  
        el.removeEventListener('click', scrollToElement);
    },
};

export default ScrollToElementDirective;